import java.util.Arrays;

public class CoinChange {
    public static void main(String[] args) {
        CoinChange contains = new CoinChange();
        int i = contains.uniquePaths(3, 2);
        System.out.println(i);

    }
    public int coinChange(int[] coins, int amount) {
        // 子问题：求已经选择了coins中的硬币的对应的最小选择数量
        // 状态数组：一维数组
        // dp方程：f(n) = min (f(n-k))+1,k in coins
        int[] dp = new int[amount+1];
        Arrays.fill(dp,amount+1);
        dp[0] = 0;
        for(int i=1;i<amount+1;i++){
            for (int j = 0; j <coins.length ; j++) {
                if(i>=coins[j]){
                    dp[i] = Math.min(dp[i],dp[i-coins[j]]+1);
                    System.out.println(i+":"+dp[i]);
                }
            }
        }
        return dp[amount] > amount?-1:dp[amount];
    }
    public int uniquePaths(int m, int n) {
        //最优子结构的问题：向下或者是向右之和的问题
        // dp状态数组：二维数组，记录同点的到终点的走法问题
        // dp方程：f(i,j) = f(i-1,j)+f(i,j-1)
        int[][] dp = new int[m][n];
        Arrays.fill(dp[0],1);
        for (int i = 0; i <m ; i++) {
            dp[i][0] = 1;
        }
        for (int i = 1; i <m ; i++) {
            for (int j = 1; j <n ; j++) {
                dp[i][j] = dp[i][j-1]+dp[i-1][j];
                System.out.println(dp[i][j]);
            }
        }
        return dp[m-1][n-1];
    }
}
